import { Component } from '@angular/core';
import { ExpressionService } from '@core/services/expression/ExpressionService';
import { Events } from '@core/services/events/Events';
import { SubjectService } from '@core/services/events/subject.service';
import { ApiService } from '@core/services/http/api.service';
import { ApesField } from '@shared/ui-zorro/src/types/apes-field';

@Component({
  selector: 'formly-field-download',
  template: `

    <div apes-col [apesMd]="24">
      <apes-form-item style="margin-bottom:0; padding: 5px 16px 0;">
        <button apes-button [apesType]="'primary'" [apesLoading]="downloading" (click)="handleDownload()" [disabled]="to.disabled">
          {{ downloading ? '下载中' : '下载' }}
        </button>
      </apes-form-item>
    </div>
  `
})

export class FormlyFieldDownload extends ApesField {

  downloading = false;

  constructor(protected apiService: ApiService, protected events: Events, protected expressionService: ExpressionService, protected subject: SubjectService) {
    super(apiService, events, expressionService, subject);
  }

  handleDownload(): void {
    this.downloading = true;
    setTimeout(()=>{
      this.downloading = false;
    },1000)
  }
}

